<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="../../../res/layuis/dist/layui.js"></script>
<script src="../../res/js/jquery-3.4.1.min.js"></script>
<link rel="stylesheet" href="../../../res/layuis/dist/css/layui.css" media="all">
<style>
form {
	margin: 20px;
}

#treeclass {
	line-height: 38px;
}

.downpanel dl dd:hover {
	background-color: inherit;
}

#asd{
padding-left: 100px;
}
</style>
</head>
<body>
	<form class="layui-form" action="" lay-filter="example">
		<input type="hidden" name="roId" id="roId">
		<div class="layui-form-item">
			<label class="layui-form-label">角色名称</label>
			<div class="layui-input-block">
				<input type="text" id="roName" name="roName" lay-verify="roName"
					autocomplete="off" placeholder="" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">模块描述</label>
			<div class="layui-input-block">
				<textarea placeholder="请输入内容" class="layui-textarea" id="roRemark" lay-verify="roRemark"
					name="roRemark"></textarea>
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">权限:</label>
		</div>
			
		<div id="asd" class="layui-form-item layui-form-text">
	
			<div class=" demo-tree" id="classtree"></div>

		</div>


		<div class="layui-form-item">
			<div class="layui-input-block">

				<button type="submit" class="layui-btn" lay-submit=""
					lay-filter="demo1">立即提交</button>
			</div>
		</div>
	</form>
	<script>
		layui.use([ 'tree', 'form' ], function() {
			var tree = layui.tree, form = layui.form;
			
			 form.verify({
				 roName: function(value){
					 if(value==""){
					        return '不能为空';
					      };
					      if(value.length > 10){
				    	  return '最多10个字符啊';
				      }
				    }
			 	, roRemark: function(value){
					      if(value.length > 50){
						    	  return '最多50个字符啊';
						      }
						    }
				    
					    
			 	 });
			
			var url2 = "../../../ModuleAction/findAlla";
			var data2 = null;
			 if (getQueryStringOne("id") != null) {
				 url2="../../../ModuleAction/findAlla2";
				  data2 ={
							roId : getQueryStringOne("id")
						};
				$("#roId").val(getQueryStringOne("id"));
				 var url = "../../../RoleAction/findbyid";
				var data = {
					roId : getQueryStringOne("id")
				};
				$.post(url, data, function(obj) {
					$("#roName").val(obj.roName);
					$("#roRemark").val(obj.roRemark);
				}) 
			} 
				
		
			
		
			$.post(url2, data2, function(obj) {
				tree.render({
					elem : '#classtree',
					data : obj,
					showCheckbox : true
				});
			});
			
			form.on('submit(demo1)', function(data) {
				var shu="";
				$.each($("#classtree input[type=checkbox]:checked"),function(index,item){
					shu+=$(this).val()+",";
				})
				var data= data.field;
				data.shu=shu;
				/*  layer.alert(JSON.stringify(data.field), {
				  title: '最终的提交信息'
				})  */
				 var url = "../../../RoleAction/addOrupdate"
				var index = parent.layer.getFrameIndex(window.name);
				$.post(url, data, function(obj) {
					if (obj.state == 1) {
						layer.msg("操作成功", {
							icon : 1,
							time : 1000
						}, function() {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
							// window.location.reload();
						})

						//window.parent.location.replace(location.href)//刷新父级页面  
					}
				}) 
				return false;
			});

		})
		function getQueryStringOne(key) {
			var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return decodeURI(r[2]);
			return null;
		}
	</script>
</body>
</html><SCRIPT ></SCRIPT>